package com.yh.dao;

import com.yh.javabean.Permission;
import com.yh.javabean.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Auther: als
 * @Date: 2024/5/27 - 05 - 27 - 10:30
 * @Description: com.yh.dao
 * @version: 1.0
 */
public interface PermissionDao {
    @Select("select * from permission")
    List<Permission> selectAll();

    @Insert("insert into permission (permissionName,url) values (#{permissionName},#{url})")
    int insertPermission(Permission permission);

    @Delete("delete from permission where id=#{id}")
    int deleteById(int id);

    @Update("update permission set permissionName=#{permissionName},url=#{url} where id=#{id}")
    int updatePermission(Permission permission);

    @Select("select * from permission where id=#{id}")
    Permission selectById(int id);

    //   模糊查询
    List<Permission> selectpermissionName(String permissionName);

    //注解模糊查询
    /*@Select("SELECT * FROM permission WHERE permissionName LIKE CONCAT('%', #{permissionName}, '%')")
    List<Permission> selectpermissionName(@Param("permissionName") String permissionName);*/

    @Select("select p.* from permission p,role_permission rp where p.id=rp.permissionId and rp.roleId=#{rid}")
    List<Permission> selectByRid(int rid);


    //批量删除权限
    @Delete("<script>" +
            "        delete from permission where id in\n" +
            "        <foreach collection=\"ids\" item=\"id\" open=\"(\" close=\")\" separator=\",\">\n" +
            "            #{id}\n" +
            "        </foreach>" +
            "</script>")
    int deleteByList(@Param("ids") List<Integer> ids);


    @Select("        select p.*\n" +
            "        from users u,role r,permission p,users_role ur,role_permission rp\n" +
            "        where u.id=ur.userId and r.id=ur.roleId and r.id=rp.roleId and p.id =rp.permissionId and u.id=#{uid}")
    List<Permission> selectByUid(int uid);
}
